Repository navigation
Conversation
Skip the terminal OSC color query for non-interactive early-exit invocations (--version/-v/--help/-h) and when NO_COLOR is set, so the terminal's reply is never left in the shell input buffer.
|
Good catch on the root cause — early-exit commands ( A few concerns on the implementation:
Worth porting in spirit, but I'd want the flag check narrowed to the top-level command token, the duplicate logic consolidated, and a couple of targeted tests before this goes in as-is. |
Fixes #1743.
Summary
Running
freebuff --versionorfreebuff --help(andNO_COLOR=1 freebuff --version) left the terminal's OSC 11 background-color reply (e.g.11;rgb:2c2c/3737/4646) sitting in the shell's input buffer.The cause: OSC 10/11 terminal theme detection started before CLI flags were parsed. For early-exit commands, Commander printed the version/help and the process exited before the terminal's reply could be read, so the reply was never consumed and leaked into the next shell prompt.
This change skips the OSC query entirely for those invocations (and when
NO_COLORis set), falling back to the existing synchronous env/fallback theme evidence. No query is written to the TTY and stdin is not switched to raw mode, so there is nothing left for the shell to read.Changes
cli/src/utils/terminal-color-detection.ts—terminalSupportsOSC()returnsfalsewhenNO_COLORis set or whenprocess.argvcontains--version/-v/--help/-h.cli/src/index.tsx—oscQuerySupportedis gated the same way, sodetectTerminalTheme()is not called for those invocations.cli/src/types/env.ts,cli/src/utils/env.ts— addNO_COLORtoCliEnvandgetCliEnv().Testing
bun test cli/src/utils/__tests__/terminal-color-detection.test.ts→ 70 pass, 0 fail.terminalSupportsOSCreturnsfalsefor--versionandNO_COLOR=1,trueotherwise.Scope
Touches only
cli/and CLI env/types; no backend, billing, deployment, or secret-management paths. Single focused fix.